package com.maowei.handler;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.otter.canal.protocol.CanalEntry;
import com.maowei.entity.BusinessOperateRecordModel;
import com.maowei.event.TableEvent;
import com.maowei.parser.RowDataCustomParser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 示例 : 监听用户变的数据变化 !!!
 * 示例 : 监听用户变的数据变化 !!!
 * 示例 : 监听用户变的数据变化 !!!
 *
 * 监听 新增和修改的变化
 * @author maowei
 * @date 2021/8/25
 */
@Slf4j
@Component
@TableEvent(tableName = "sys_user",eventTypes = CanalEntry.EventType.UPDATE)
public class SysUserEventHandler extends BaseEventHandler {

    /**
     * 关注变化的字段
     */
    private static final List<String> FOCUSE_COLUMS;

    static{
        FOCUSE_COLUMS = new ArrayList<>(16);
//        用户名 user_name
        FOCUSE_COLUMS.add("user_name");
    }

    @Autowired
    public SysUserEventHandler(RowDataCustomParser rowDataCustomParser) {
        super(rowDataCustomParser);
    }

    @Override
    public void doHandle(JSONObject jsonObject) {
        this.print(jsonObject);
//        BusinessOperateRecordModel businessOperateRecordModel = this.parse(jsonObject, true, null);
        BusinessOperateRecordModel businessOperateRecordModel = this.parse(jsonObject, false, FOCUSE_COLUMS);
        log.info("用户表 - 修改操作记录 : {}",businessOperateRecordModel);
        toDB(businessOperateRecordModel);
    }

}
